package com.lyandwc.lw_bbs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyandwc.lw_bbs.dao.TagDao;
import com.lyandwc.lw_bbs.entity.Tag;
import com.lyandwc.lw_bbs.service.TagService;
import org.springframework.stereotype.Service;

@Service
public class TagServiceImpl extends ServiceImpl<TagDao, Tag> implements TagService {
    @Override
    public Tag findOrInsertTag(String name) {
        Tag tag = this.baseMapper.selectOne(
                new QueryWrapper<Tag>().lambda()
                        .eq(Tag::getName, name)
        );
        if (tag == null) {
            tag = new Tag();
            tag.setName(name);
            this.save(tag);
        }
        return tag;
    }
}
